package cn.com.blackboard.SISIntergrationBiz.controller;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cm.com.blackboard.DataModule4B2.customizeConfigUtils.DataSourceKeyUtil;
import cn.com.blackboard.DataModule4B2.BBDataUtils.LocaleUtil;
import cn.com.blackboard.DataModule4B2.util.DataSourceModel;
  
@Controller
@RequestMapping("/datasource")
public class DatasourcekeySetController {  
	
	private static final Logger logger = LoggerFactory.getLogger(DatasourcekeySetController.class);
    
    @RequestMapping("/load")  
    public String getProps(ModelMap modelMap) throws IOException{	
    	logger.info("into load controller");
    	
		modelMap.addAttribute("dataSourceModelList", DataSourceKeyUtil.getDataSourceModelList());	
		Locale locale = LocaleUtil.getLocale();
		modelMap.addAttribute("locale", locale.toString());
		
		return "/config/configExtentionAttr"; 
    }
    
    @RequestMapping(value = "set", method = {RequestMethod.POST },produces={"text/html;charset=UTF-8;","application/json;"})
    @ResponseBody
    public String setProps(@RequestBody List<DataSourceModel> list) throws IOException{	
    	logger.info("into set controller");

    	DataSourceKeyUtil.setAndPersistExtentionList(list);

		return ""; 
    }

}  
